import { ref } from 'vue'
import { EmployeeApi } from '@/apis'
import type { EmployeeType } from '@/apis/system/employee'

/** 员工模块 */
export function useEmployee(options?: { onSuccess?: () => void }) {
  const loading = ref(false)
  const employeeList = ref<EmployeeApi.EmployeeResp[]>([])

  const getEmployeeList = async (type?: EmployeeType) => {
    try {
      loading.value = true
      employeeList.value = await EmployeeApi.getList({
        status: 1,
        type,
      })
      options?.onSuccess?.()
    } finally {
      loading.value = false
    }
  }
  return { employeeList, getEmployeeList, loading }
}
